package controller

import (
	"encoding/json"
	"go.uber.org/zap"
	"kf/models/dao"
	"kf/tools"
	"kf/ws"
	"log"
)

type ShoutController struct {
	ConfigDao     *dao.ConfigDao
	UserClientDao *dao.UserClientDao
	Log           *zap.Logger
	WsUser        *ws.WsUser
}

func (shoutController *ShoutController) SendVisitorLoginNotice(kefuName, visitorName, avator, content, visitorId string) {
	if !tools.LimitFreqSingle("sendnotice:"+visitorId, 1, 120) {
		log.Println("SendVisitorLoginNotice limit")
		return
	}
	userInfo := make(map[string]string)
	userInfo["username"] = visitorName
	userInfo["avator"] = avator
	userInfo["content"] = content
	msg := ws.TypeMessage{
		Type: "notice",
		Data: userInfo,
	}
	str, _ := json.Marshal(msg)
	shoutController.WsUser.OneKefuMessage(kefuName, str)
}
